pragma Singleton
import QtQuick 2.14

QtObject {
    id: appStyle
    
    // 颜色主题
    readonly property QtObject colors: QtObject {
        // 主色调
        readonly property color primary: "#2196F3"
        readonly property color primaryDark: "#1976D2"
        readonly property color primaryLight: "#BBDEFB"
        
        // 辅助色调
        readonly property color accent: "#FF4081"
        readonly property color accentDark: "#C2185B"
        readonly property color accentLight: "#F8BBD9"
        
        // 状态颜色
        readonly property color success: "#4CAF50"
        readonly property color warning: "#FF9800"
        readonly property color error: "#F44336"
        readonly property color info: "#2196F3"
        
        // 文本颜色
        readonly property color textPrimary: "#212121"
        readonly property color textSecondary: "#757575"
        readonly property color textHint: "#BDBDBD"
        readonly property color textOnPrimary: "#FFFFFF"
        
        // 背景颜色
        readonly property color background: "#FAFAFA"
        readonly property color surface: "#FFFFFF"
        readonly property color surfaceDark: "#F5F5F5"
        
        // 边框颜色
        readonly property color border: "#E0E0E0"
        readonly property color borderFocus: "#2196F3"
        readonly property color borderError: "#F44336"
        
        // 阴影颜色
        readonly property color shadow: "#40000000"
        readonly property color shadowLight: "#20000000"
    }
    
    // 字体设置
    readonly property QtObject fonts: QtObject {
        readonly property int tiny: 10
        readonly property int small: 12
        readonly property int normal: 14
        readonly property int medium: 16
        readonly property int large: 18
        readonly property int xlarge: 20
        readonly property int xxlarge: 24
        readonly property int huge: 28
        
        readonly property string family: "Microsoft YaHei UI"
        readonly property string familyMono: "Consolas"
    }
    
    // 间距设置
    readonly property QtObject spacing: QtObject {
        readonly property int tiny: 4
        readonly property int small: 8
        readonly property int normal: 12
        readonly property int medium: 16
        readonly property int large: 20
        readonly property int xlarge: 24
        readonly property int xxlarge: 32
        readonly property int huge: 40
    }
    
    // 圆角设置
    readonly property QtObject radius: QtObject {
        readonly property int small: 2
        readonly property int normal: 4
        readonly property int medium: 6
        readonly property int large: 8
        readonly property int xlarge: 12
        readonly property int round: 50
    }
    
    // 动画设置
    readonly property QtObject animation: QtObject {
        readonly property int fast: 100
        readonly property int normal: 200
        readonly property int slow: 300
        readonly property int verySlow: 500
    }
    
    // 尺寸设置
    readonly property QtObject sizes: QtObject {
        // 按钮尺寸
        readonly property int buttonHeightSmall: 28
        readonly property int buttonHeightNormal: 36
        readonly property int buttonHeightLarge: 44
        
        // 输入框尺寸
        readonly property int inputHeightSmall: 32
        readonly property int inputHeightNormal: 40
        readonly property int inputHeightLarge: 48
        
        // 图标尺寸
        readonly property int iconSmall: 16
        readonly property int iconNormal: 20
        readonly property int iconMedium: 24
        readonly property int iconLarge: 32
        readonly property int iconXLarge: 48
        
        // 头像尺寸
        readonly property int avatarSmall: 24
        readonly property int avatarNormal: 32
        readonly property int avatarMedium: 40
        readonly property int avatarLarge: 56
        
        // 导航栏
        readonly property int navigationBarWidth: 240
        readonly property int navigationBarItemHeight: 48
        
        // 工具栏
        readonly property int toolbarHeight: 56
        readonly property int statusBarHeight: 24
    }
    
    // 阴影设置
    readonly property QtObject shadows: QtObject {
        readonly property QtObject elevation1: QtObject {
            readonly property int offsetX: 0
            readonly property int offsetY: 1
            readonly property int radius: 3
            readonly property color color: appStyle.colors.shadow
        }
        
        readonly property QtObject elevation2: QtObject {
            readonly property int offsetX: 0
            readonly property int offsetY: 2
            readonly property int radius: 6
            readonly property color color: appStyle.colors.shadow
        }
        
        readonly property QtObject elevation3: QtObject {
            readonly property int offsetX: 0
            readonly property int offsetY: 3
            readonly property int radius: 12
            readonly property color color: appStyle.colors.shadow
        }
    }
    
    // 工具函数
    function getStatusColor(status) {
        switch (status.toLowerCase()) {
            case "success":
            case "completed":
            case "active":
                return colors.success
            case "warning":
            case "pending":
                return colors.warning
            case "error":
            case "failed":
            case "inactive":
                return colors.error
            case "info":
            case "running":
            default:
                return colors.info
        }
    }
    
    function getContrastColor(backgroundColor) {
        // 简单的对比度计算，返回黑色或白色
        var r = parseInt(backgroundColor.toString().substr(1, 2), 16)
        var g = parseInt(backgroundColor.toString().substr(3, 2), 16)
        var b = parseInt(backgroundColor.toString().substr(5, 2), 16)
        var brightness = (r * 299 + g * 587 + b * 114) / 1000
        return brightness > 128 ? colors.textPrimary : colors.textOnPrimary
    }
    
    function withOpacity(color, opacity) {
        return Qt.rgba(color.r, color.g, color.b, opacity)
    }
}